//
//  SEGMessageNaviTitleNomalView.m
//  ExcellentHome
//
//  Created by 刘山 on 2016/10/23.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "SEGMessageNaviTitleNomalView.h"
//#import "SEGSEGBasicKitLayoutDefine.h"
#import <Masonry/Masonry.h>

@interface SEGMessageNaviTitleNomalView ()
@property (nonatomic, strong) UIButton* titleBtn;
@property (nonatomic, strong) UIButton* shareBtn;
@end

@implementation SEGMessageNaviTitleNomalView
- (instancetype)init
{
    if (self == [super init]) {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.userInteractionEnabled = YES;
    self.backgroundColor = [UIColor whiteColor];

    self.layer.borderColor = kColor_L2.CGColor;
    self.layer.borderWidth = 0.5;

    [self addSubview:self.titleBtn];
    [self addSubview:self.contentLabel];

    [self.titleBtn setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"back")] forState:UIControlStateNormal];

    [self.titleBtn addTarget:self action:@selector(titleBtnClick:) forControlEvents:UIControlEventTouchUpInside];

    [self.titleBtn sizeToFit];
    [self.titleBtn mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self).mas_offset(15);
        make.centerY.equalTo(self).multipliedBy(1.3);
    }];

    self.contentLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerY.equalTo(self).multipliedBy(1.3);
        make.left.equalTo(self.mas_left).mas_offset(40);
        make.right.equalTo(self.mas_right).mas_offset(-40);
    }];
    
//    self.titleBtn.backgroundColor = kColor_T;
//    self.contentLabel.backgroundColor = kColor_S1;
//    self.shareBtn.backgroundColor = kColor_S2;
}

- (void)showShareButton
{
    [self addSubview:self.shareBtn];
    
    UIImage *image = [[UIImage imageWithContentsOfFile:SEGPicName(@"icon_more_black")] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    [self.shareBtn setImage:image forState:UIControlStateNormal];
    [self.shareBtn setTintColor:kColor_1];
    [self.shareBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.shareBtn sizeToFit];
    [self.shareBtn mas_makeConstraints:^(MASConstraintMaker* make) {
        make.right.equalTo(self).mas_offset(0);
        make.centerY.equalTo(self).multipliedBy(1.3);
        make.width.mas_equalTo(50);//各加15边距
        make.height.mas_equalTo(45);
    }];
}

- (void)titleBtnClick:(UIButton*)sender
{
    if (self.btnDelegate && [self.btnDelegate respondsToSelector:@selector(naviTitleNomalViewBackButtonPressed)]) {
        [self.btnDelegate naviTitleNomalViewBackButtonPressed];
    }
}

- (void)shareBtnClick:(UIButton*)sender
{
    if (self.btnDelegate && [self.btnDelegate respondsToSelector:@selector(naviTitleNomalViewShareButtonPressed)]) {
        [self.btnDelegate naviTitleNomalViewShareButtonPressed];
    }
}

- (UIButton*)titleBtn
{
    if (!_titleBtn) {
        _titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _titleBtn;
}


- (UILabel*)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
    }
    return _contentLabel;
}


- (UIButton*)shareBtn
{
    if (!_shareBtn) {
        _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _shareBtn;
}

@end
